// src/api/dish.ts
import request from '@/utils/request';
// 导入我们将在模型层创建的类型
import type { IDish, IDishPageResult, IDishPageQuery, IDishAddDTO, IDishEditDTO } from '@/types/dish';

/**
 * 菜品分页查询
 * @param params - 查询参数
 */
export const getDishPage = (params: IDishPageQuery) => {
  return request<IDishPageResult>({
    url: '/dish/page',
    method: 'get',
    params
  });
};

/**
 * 新增菜品
 * @param data - 菜品数据
 */
export const addDish = (data: IDishAddDTO) => {
  return request({
    url: '/dish',
    method: 'post',
    data
  });
};

/**
 * 修改菜品
 * @param data - 菜品数据
 */
export const editDish = (data: IDishEditDTO) => {
  return request({
    url: '/dish',
    method: 'put',
    data
  });
};

/**
 * 根据id查询菜品
 * @param id - 菜品id
 */
export const getDishById = (id: number) => {
  return request<IDish>({
    url: `/dish/${id}`,
    method: 'get'
  });
};

/**
 * 批量删除菜品
 * @param ids - 菜品id字符串，以逗号分隔
 */
export const deleteDish = (ids: string) => {
  return request({
    url: '/dish',
    method: 'delete',
    params: { ids }
  });
};

/**
 * 菜品起售、停售
 * @param params - 包含 status 和 id
 */
export const updateDishStatus = (params: { status: 0 | 1; id: number }) => {
  return request({
    url: `/dish/status/${params.status}`,
    method: 'post',
    params: { id: params.id }
  });
};

/**
 * 根据分类id查询菜品
 * @param params - { categoryId }
 */
export const getDishListByCategoryId = (params: { categoryId: number }) => {
  return request<IDish[]>({
    url: '/dish/list',
    method: 'get',
    params
  });
};
